import 'dart:ui';

import 'package:flutter/material.dart';
import 'shared/size_fit.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    HYSizeFit.initialize();

    // 1.手机的物理分辨率
    var physicalWidth = window.physicalSize.width;
    var physicalHeight = window.physicalSize.height;
    print('分辨率:$physicalWidth * $physicalHeight');

    //2.手机屏幕的大小(逻辑分辨率) 放在这里会报错(context还没初始化完)
    // var width2 = MediaQuery.of(context).size.width;
    // var height2 = MediaQuery.of(context).size.height;

    //3.另一种获取屏幕的大小,获取dpr
    var dpr = window.devicePixelRatio;
    var width = physicalWidth / dpr;
    var height = physicalHeight / dpr;
    print('屏幕宽高:$width * $height');

    //4.状态栏高度
    var statusHeight = window.padding.top / dpr;
    print('状态栏高度:$statusHeight');

    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.teal),
      debugShowCheckedModeBanner: false,
      home: HYHomePage(),
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //2.手机屏幕的大小(逻辑分辨率)
    var width = MediaQuery.of(context).size.width;
    var height = MediaQuery.of(context).size.height;
    var statusHeight = MediaQuery.of(context).padding.top;
    print('屏幕宽高2:$width * $height, 状态栏高度:$statusHeight');
    print(HYSizeFit.physicalHeight);
    return Scaffold(
        appBar: AppBar(
          title: Text('Flutter Demo'),
        ),
        body: Center(child: Text('Hello Flutter')),
        floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: () => print('FloatingActionButton click')),
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat);
  }
}
